<?php
if ($paging->pages > 1) {

$number_links = 1 + (isset($add_number_links) ? $add_number_links : 1);
$url = $params["url"]["url"];
if (strpos($url, '/') !== 0) {
    $url = '/'.$url;
}
?><div class="paging"><?php
?><div class="pages"><?php
?><div class="paging-centered"><?php


    $cells = array();
    $next_cells = array();
    if ($paging->currentPage > 1) {
        if ($paging->currentPage - $number_links > 1) {
            $cells[] = $paging->drawLink($html, $url, 1);
            if ($paging->prev-$number_links > 1) {
                if ($paging->prev-$number_links > 2) {
                    $cells[] = '<td class="sys_clear">&hellip;</td>';
                } else {
                    $cells[] = $paging->drawLink($html, $url, 2);
                }
            }
        }
        for ($i = max(1, $paging->currentPage - $number_links); $i < $paging->currentPage; $i++) {
            $cells[] = $paging->drawLink($html, $url, $i);
        }
    }

    $next_cells[] = $paging->drawLink($html, $url, $paging->currentPage);

    if ($paging->currentPage < $paging->pages) {
        $max_pages = min($paging->pages, $paging->currentPage + $number_links);
        for ($i = $paging->currentPage + 1; $i <= $max_pages; $i++) {
            $next_cells[] = $paging->drawLink($html, $url, $i);
        }

        if ($max_pages < $paging->pages) {
            if ($paging->pages - $max_pages > 1) {
                if ($paging->pages - $max_pages > 2) {
                    $next_cells[] = '<td class="sys_clear">&hellip;</td>';
                } else {
                    $next_cells[] = $paging->drawLink($html, $url, $max_pages+1);
                }
            }
            $next_cells[] = $paging->drawLink($html, $url, $paging->pages);
        }
    }
    if (strlen($last_page_link = $paging->drawLink($html, $url, Pagination::pageLast))) {
        $next_cells[] = $last_page_link;
    }

?><table class="paging-table sys_clear" cellpadding="0"><?php
?><tr class="sys_clear"><?php
        for ($i = 0; $i < $number_links + 2 - count($cells); $i++) {
            ?><td class="cell sys_clear"><span></span></td><?php
        }
        for ($i = 0; $i < count($cells); $i++) {
            ?><?=$cells[$i];?><?php
        }
        for ($i = 0; $i < count($next_cells); $i++) {
            ?><?=$next_cells[$i];?><?php
        }
?></tr><?php
?></table><?php
?></div><?php
?></div><?php
?></div><?php
} ?>